#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	string s, t;
	cin >> s >> t;
	int i, j;
	for (i = 0, j = 0; i < s.size() && j < t.size();)
	{
		int cnt1 = 0, cnt2 = 0;
		char now1 = s[i], now2 = t[j];
		if (now1 != now2)
		{
			cout << "NO" << endl;
			return;
		}
		while (i < s.size()) if (s[i] == now1) i++, cnt1++; else break;
		while (j < t.size()) if (t[j] == now2) j++, cnt2++; else break;
		if (cnt1 > cnt2 || cnt2 > 2 * cnt1)
		{
			cout << "NO" << endl;
			return;
		}
	}
	if (i != s.size() || j != t.size())
	{
		cout << "NO" << endl;
		return;
	}
	cout << "YES" << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}